#! /bin/sh
LINES=18
COMMANDS=Commands_Only
WIDTH=400
XOFF1=425
XOFF2=850
HEIGHT=400
YOFF1=50
YOFF2=500

indata=data.seis
outdata1=data.fullfold
outdata2=data.sortdown
outdata3=data.unsort
outdata4=data.recgather
outdata5=data.stack
outdata6=data.near
outdata7=data.far

# First make the synthetic data for the sorting demo.
######START OF MODEL######
REF1="1.0:-2,0.2;4,0.2"
REF2="1.0:-2,2.0199;3.5495,0"
REF3="1.0:-2,4.3955;3.2384,0"
REF4="1.0:-2,8.8603;3.1155,0"

dvdz=.015  # velocity gradient (dv/dz)
dvdx=-0.2  # velocity gradient (dv/dx)
v00=5.0  # P-wave velocity at surface (S-wave velocity for GAMM>>1) in km/s
nxo=6 fxo=0.04 dxo=0.04 # offset information: number, first and spacing
nxs=12 fxs=1.0 dxs=0.04 # shot information: number, first and spacing
nt=200 dt=0.004         # time information: number and spacing

susynlv v00=$v00 ndpfz=10 dvdz=$dvdz dvdx=$dvdx \
		dt=$dt nt=$nt verbose=0 \
		ref=$REF1 ref=$REF2 ref=$REF3 ref=$REF4 \
		nxo=$nxo fxo=$fxo dxo=$dxo \
		nxs=$nxs fxs=$fxs dxs=$dxs  |
suchw key1=cdp key2=gx key3=sx b=1 c=1 d=2  >$indata
######END OF MODEL######
suximage <$indata perc=99 title="Shot Gathers" \
	label1="Time (sec)" label2="Shot Gather" f2=1 d2=0.166667   \
	wbox=${WIDTH} hbox=${HEIGHT} xoff=0 yoff=${YOFF1} &
 
# SORTING EXAMPLES
# Use surange to get overview of header values set, etc.
sleep 3
surange <$indata

# Get a stacking chart
suchart <$indata |                     
xgraph n=72 title="Stacking Chart" label1="sx" label2="gx" \
 linecolor=3 linewidth=0 marksize=3 mark=8 \
 -geometry ${WIDTH}x${HEIGHT}+${XOFF1}+${YOFF1} &

# Find region of full fold
susort <$indata > temp
sugethw < temp cdp offset

# Window to full fold region and sort by cdp and offset
suwind <$indata key=cdp min=1100 max=1480 > temp
susort < temp cdp offset >$outdata1
sugethw<$outdata1 cdp offset | sed ${LINES}q
suximage <$outdata1 perc=99 title="CDP and +Offset" \
	label1="Time (sec)" label2="CDP Gather" f2=1 d2=0.333333 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF2} ybox=${YOFF1} &

# sort data by decreasing cdp and within each cdp by offset
sleep 3
susort <$outdata1 cdp -offset >$outdata2 
sugethw <$outdata2 cdp offset | sed ${LINES}q
suximage <$outdata2 perc=99\
	title="CDP and -Offset"\
 	label1="Time (sec)" label2="CDP Gather" f2=1 d2=0.333333 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=0 ybox=${YOFF2} &
 

# reconstruct windowed data $outdata1 from $outdata2
sleep 3
susort <$outdata2 cdp offset >$outdata3
sudiff $outdata1 $outdata3 | sumax

# make receiver gathers from shot gathers
susort <$indata gx offset >$outdata4
sugethw <$outdata4 gx sx cdp offset | sed ${LINES}q
suximage <$outdata4 perc=99 title="Receiver gathers"\
	label1="Time (sec)" label2="Receiver Gather" f2=1 d2=1  \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF1} ybox=${YOFF2} &

# application: stacking
sleep 3
susort <$outdata1 |
sustack >$outdata5
sugethw <$outdata5 cdp nhs | sed ${LINES}q
suxwigb <$outdata5 perc=99 title="Stacked Data"\
	label1="Time (sec)" label2="CDP Location" f2=1100 d2=20 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF2} ybox=${YOFF2} &

# get near and far common offset sections (doesn't use susort, but ...)
sleep 3
suwind <$indata key=offset min=40 max=80 >$outdata6
sugethw <$outdata6 cdp offset | sed ${LINES}q
suxwigb <$outdata6 perc=99 title="Near Offsets"\
	label1="Time (sec)" label2="CDP Location" f2=1020 d2=20 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF1} ybox=50 &

sleep 3
suwind <$indata key=offset min=200 max=240 >$outdata7
sugethw <$outdata7 cdp offset | sed ${LINES}q
suxwigb <$outdata7 perc=99 title="Far Offsets"\
	label1="Time (sec)" label2="CDP Location" f2=1100 d2=20 \
	wbox=${WIDTH} hbox=${HEIGHT} xbox=${XOFF2} ybox=50 &
exit
